package com.backend.system.service.processors.user;

import com.backend.system.beans.DeleteReq;
import com.backend.system.common.annotation.ProcessorBean;
import com.backend.system.common.enums.ActionTypeEnum;
import com.backend.system.common.processor.AbstractProcessorTemplate;
import com.backend.system.common.processor.ProcessorContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 删除用户处理器
 *
 * @author backend-manage
 */
@Slf4j
@Component
@ProcessorBean(action = ActionTypeEnum.USER_DELETE)
public class UserDeleteProcessor extends AbstractProcessorTemplate<DeleteReq, Boolean> {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean handle(ProcessorContext<DeleteReq> context) {
        DeleteReq req = context.getData();
        userService.removeById(req.getId());
        roleUserService.removeByUserId(req.getId());
        return true;
    }
}
